package wolftrace_company.study_android_ui.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;

import wolftrace_company.study_android_ui.R;

/**
 * Created by SimpleTonOne on 2018/4/20.
 */

public class MySpinnerActivity extends AppCompatActivity {
    private Spinner spinner;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        setContentView(R.layout.myspinneractivity);
        spinner = findViewById(R.id.spinner1);
        ArrayAdapter arrayAdapter = ArrayAdapter.createFromResource(this,R.array.myArray,R.layout.spinner_style);
        arrayAdapter.setDropDownViewResource(R.layout.spinner_dropdowm_style);
        spinner.setAdapter(arrayAdapter);
        spinner.setSelection(3);
        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                String selectInfo = parent.getItemAtPosition(position).toString();
                Toast.makeText(MySpinnerActivity.this,selectInfo,Toast.LENGTH_LONG).show();
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
    }

}

